1. Statement of the Technical Field
The present invention relates to computer programming language processing and more particularly to managing program function parameters using compiler directives.
2. Description of the Related Art
Both structural and functional programming languages specify the function or method mechanism through which computing logic can be compartmentalized into a manageable and reusable form. The conventional function or method (the terms are often used interchangeably) includes a prototype and a body. The prototype often specifies a function name, one or more parameter types for processing in the body, and a return type. The body, in turn, contains program statements which can act upon data local to the function, data external to the function, and data provided through the prototype interface in the form of parameters. Optionally, the body can specify a return value which can be passed out of the function to the calling logic.
Functions operate on the parameters passed into the function through the prototype structure. Consequently, the data types of the parameters can be fixed according to the function definition provided by the prototype. In this regard, where a function is to operate on a variety of different data types for the same parameters, different versions of the function must be created for use in each specific instance for a particular parameter data type. Even where a single function is configured to handle different data types for the same parameter, the logic must be duplicated within the function body and selected according to a selector parameter provided at the time of calling the function.
Notably, designing different functions to handle different data types for the same parameter can be problematic not only from the design standpoint in that different logic will be required for each data type, but also from the perspective that a developer utilizing the function will be required to maintain firm knowledge of the required data types for the parameters when calling the function externally. To overcome at least the latter problem, some modem third-generation languages provide for function overloading. Function overloading permits the end user to call a function using the desired data types as parameters to the function call without requiring the end user to maintain a firm awareness of the specified data types in the function prototype. Rather, the actual use of parameters in the function call can be recognized by the compiler as a selection of the correct version of the function to handle the data types of the actual parameters.
Nevertheless, many heavily utilized third generation programming languages do not support function overloading for several reasons, the principal reason relating to the heavy-weight nature of the implementation of function overloading. To provide some semblance of function overloading, however, some programming language implementations support type-generic macros. Type generic macros mimic functional overloading in that either compile time logic of the compiler, or run-time logic of the application can determine the data types of supplied parameters to a function to select an appropriate function to execute.
For instance, in the C programming language, the size of operator can be applied to supplied parameters in a generic macro form of the called function to detect the data types of the parameters. Using the sizeof data, an appropriate specific form of the actual function can be called. It will be recognized, however, that the run-time solution can be code intensive and can result in a performance penalty based upon the necessity to perform comparisons. More importantly, though, where two or more data types have the same size, the sizeof operator will be ineffectual in differentiating between the different data types.
In an alternative implementation, the compiler can be configured to detect a call to a generic form of the function. Referring to an internal compiler table, the compiler can detect the data types of supplied parameters to the generic function to choose an appropriate specific form of the function. Notably, to implement the latter solution, access to the logic of the compiler will be required which can inhibit the modification and management of permissible function prototype forms. Consequently, the latter solution will be ineffectual in the case where a library is to be developed by third-party vendors who do not have access to the internal compiler tables.